home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / windows / ocx / ipack.exe / CLIENT32.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-09-23  |  4.9 KB  |  163 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Socket Client"
  5.    ClientHeight    =   3615
  6.    ClientLeft      =   1515
  7.    ClientTop       =   1950
  8.    ClientWidth     =   6855
  9.    Height          =   4020
  10.    Left            =   1455
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   3615
  15.    ScaleWidth      =   6855
  16.    ShowInTaskbar   =   0   'False
  17.    Top             =   1605
  18.    Width           =   6975
  19.    Begin VB.TextBox textMessageEntry 
  20.       Height          =   900
  21.       Left            =   1560
  22.       TabIndex        =   0
  23.       Top             =   2475
  24.       Width           =   5055
  25.    End
  26.    Begin VB.ListBox listTranscript 
  27.       Height          =   1815
  28.       Left            =   240
  29.       MultiSelect     =   1  'Simple
  30.       TabIndex        =   3
  31.       TabStop         =   0   'False
  32.       Top             =   330
  33.       Width           =   6375
  34.    End
  35.    Begin AsocketLib.AsyncSocket AsyncSocket1 
  36.       Left            =   960
  37.       Top             =   2880
  38.       _Version        =   327680
  39.       _ExtentX        =   847
  40.       _ExtentY        =   847
  41.       _StockProps     =   0
  42.       ReceiveBufferSize=   8192
  43.       SendBufferSize  =   8192
  44.       BroadcastEnabled=   0   'False
  45.       LingerEnabled   =   0   'False
  46.       RouteEnabled    =   -1  'True
  47.       KeepAliveEnabled=   0   'False
  48.       OutOfBandEnabled=   0   'False
  49.       ReuseAddressEnabled=   0   'False
  50.       TCPNoDelayEnabled=   0   'False
  51.       LingerMode      =   0
  52.       LingerTime      =   0
  53.       EventMask       =   63
  54.       LocalPort       =   0
  55.       RemotePort      =   0
  56.       SocketType      =   0
  57.       LocalAddress    =   ""
  58.       RemoteName      =   ""
  59.       RemoteAddress   =   ""
  60.       ReceiveTimeout  =   -1
  61.       SendTimeout     =   -1
  62.    End
  63.    Begin VB.Label Label2 
  64.       Alignment       =   1  'Right Justify
  65.       Caption         =   "Enter Message and Press Enter:"
  66.       Height          =   570
  67.       Left            =   240
  68.       TabIndex        =   1
  69.       Top             =   2445
  70.       Width           =   1215
  71.    End
  72.    Begin VB.Line Line2 
  73.       BorderColor     =   &H00808080&
  74.       X1              =   240
  75.       X2              =   6600
  76.       Y1              =   2310
  77.       Y2              =   2310
  78.    End
  79.    Begin VB.Line Line1 
  80.       BorderColor     =   &H00FFFFFF&
  81.       X1              =   240
  82.       X2              =   6600
  83.       Y1              =   2340
  84.       Y2              =   2340
  85.    End
  86.    Begin VB.Label Label1 
  87.       Caption         =   "Transcript:"
  88.       Height          =   225
  89.       Left            =   240
  90.       TabIndex        =   2
  91.       Top             =   75
  92.       Width           =   900
  93.    End
  94. Attribute VB_Name = "Form1"
  95. Attribute VB_Creatable = False
  96. Attribute VB_Exposed = False
  97. Option Explicit
  98. Private Sub AsyncSocket1_OnClose(ByVal ErrorCode As Integer)
  99.    ' Close the program if our server goes away
  100.    Unload Me
  101.    End Sub
  102. Private Sub AsyncSocket1_OnReceive(ByVal ErrorCode As Integer)
  103.    Dim t As String
  104.    ' Get the text received
  105.    t = AsyncSocket1.Receive()
  106.    ' If all we have is a carriage return ...
  107.    If (Len(t) = 1 And Asc(Left(t, 1)) = 13) Then
  108.       ' ... just use a blank string.
  109.       t = ""
  110.       End If
  111.       
  112.    ' Add our new string to the transcript
  113.    listTranscript.AddItem t
  114.    listTranscript.ListIndex = listTranscript.ListCount - 1
  115.    End Sub
  116. Private Sub Form_Load()
  117.    Me.Show
  118.    ' Get the server's IP address.
  119.    frmEnterIP.Show 1
  120.    ' If the user pressed Esc/Cancel exit.
  121.    If AsyncSocket1.RemoteAddress = "" Then
  122.       End
  123.       End If
  124.    ' Set up the socket control.
  125.    AsyncSocket1.RemoteNameAddrXlate = False
  126.    AsyncSocket1.RemotePort = 1024
  127.    AsyncSocket1.LocalAddress = "0.0.0.0"
  128.    AsyncSocket1.LocalPort = 0
  129.    AsyncSocket1.Create
  130.    ' Connect to the server.
  131.    On Error Resume Next
  132.    AsyncSocket1.Connect
  133.    If (Err <> 0 And Err <> 10035) Then
  134.       MsgBox Error
  135.       End If
  136.    On Error GoTo 0
  137.    End Sub
  138. Private Sub Form_Unload(Cancel As Integer)
  139.    ' Disconnect from test server
  140.    AsyncSocket1.Close
  141.    End Sub
  142. Private Sub textMessageEntry_KeyPress(KeyAscii As Integer)
  143.    Dim t As String
  144.    ' Did the user press Enter?
  145.    If (KeyAscii = 13) Then
  146.       t = textMessageEntry.Text
  147.       If (textMessageEntry.Text = "") Then
  148.          t = Chr$(13)
  149.          End If
  150.       '
  151.       ' If you want to send a string containing binary data
  152.       ' you must assign it to SendBuffer and then use Send
  153.       ' without any arguments.  If you use Send strTemp VB
  154.       ' will truncate the string at the first chr$(0) if it
  155.       ' contains any.
  156.       '
  157.       AsyncSocket1.SendBuffer = t
  158.       AsyncSocket1.Send
  159.       textMessageEntry.Text = ""
  160.       KeyAscii = 0
  161.       End If
  162.    End Sub
  163.